const fs = require('fs');
const http = require('http');

http
    .createServer((req, res) => {
        res.setHeader("Content-Type", "text/html;charset=utf-8");
        if (req.url == "/" || req.url == "/favicon.ico") {
            res.end('你好');
        } else {
            try {
                const strHtml = fs.readFileSync('./public' + req.url).toString();
                res.end(strHtml);
            } catch (err) {
                res.statusCode = 404;
                res.end('404');
            }
        }
    })
    .listen(3333);